package com.java.web.excel;

import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.java.web.util.ExcelUtils;

public class ExcelExportServlet extends HttpServlet {

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse response)
			throws ServletException, IOException {
		// response.reset(); 如果前面使用过response则需要reset一下

		OutputStream outputStream = response.getOutputStream();

		response.setContentType("application/msexcel");
		response.addHeader("Content-Disposition", "attachment; filename="
				+ new String("旅游团派工单.xls".getBytes("gbk"), "iso-8859-1"));
		String[][]rowsColumns=new String[5][10];
		for(int i=0;i<rowsColumns.length;i++){
			for(int j=0;j<rowsColumns[i].length;j++){
				rowsColumns[i][j]="这是第" + (i + 1) + "行，第"  
                + (j + 1) + "列";
			}
		}
        ExcelUtils.writeExcel(outputStream, rowsColumns);
       
	}

}
